#pragma once

extern "C" {
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/imgutils.h>
#include <libavutil/timestamp.h>
// #include <libswscale/swscale.h>

#include "hb_comm_venc.h"
#include "hb_comm_vdec.h"
#include "hb_venc.h"
#include "hb_vdec.h"
#include "hb_vio_interface.h"
#include "hb_sys.h"
#include "ion.h"
}

#include "camera/hikbase.h"
#include "stream/total_struct.h"
#include "stream/horizon/stream_puller_base.h"

namespace stream {

struct cam_buffer
{
  void* start;
  unsigned int length;
};


class HBStreamPullerUSB: public HBStreamPullerBase
{
public:
  HBStreamPullerUSB(StreamPullerInfo* sifo, LogInfo* log_info);
  ~HBStreamPullerUSB();

public:

  int init_params();
  int start_pull();

  int get_frame(stream::ImageBlob& buffer);

private:
  int start_pull_imp();
  int start_pull_listener();
  int start_pull_listener_imp();

  int openDevice();
  int closeDevice();
  int initDevice();
  int startCapture();
  int stopCapture();
  int freeBuffers();
  int getFrame(void **,size_t *);
  int backFrame();
  int initBuffers();

public: 


private:
  
  std::string devName;
  int fd_cam;
  cam_buffer *buffers;
  unsigned int n_buffers;
  int frameIndex;



};


}   // namespace camera
